import 'package:tiktokadult/tools_base/debug_log.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';

import '../../../config/address.dart';
import '../../hj_page/mine_business/chat/widget/chat_msg_type.dart';
import '../mine/base_res.dart';

class MessageBean extends BaseItem {
  MessageBean({
    this.content,
    this.contentType,
    this.createdAt,
    this.id,
    this.imgUrl,
    this.isRead,
    this.sendAvatar,
    this.sendName,
    this.sendUid,
    this.sessionId,
    this.takeAvatar,
    this.takeName,
    this.takeUid,
  });
  ChatMessageType get type => globalStore.isMe(takeUid?.toInt()) ? ChatMessageType.received : ChatMessageType.sent;

  MessageBean.fromJson(dynamic json) {
    content = json['content'];
    contentType = json['contentType'];
    createdAt = json['createdAt'];
    id = json['id'];
    imgUrl = json['imgUrl'] != null ? json['imgUrl'].cast<String>() : [];
    isRead = json['isRead'];
    sendAvatar = json['sendAvatar'];
    sendName = json['sendName'];
    sendUid = json['sendUid'];
    sessionId = json['sessionId'];
    takeAvatar = json['takeAvatar'];
    takeName = json['takeName'];
    takeUid = json['takeUid'];
  }

  MessageBean.fromGoodsJson(dynamic json, dynamic userJson) {
    content = json['text'];
    createdAt = json['createdAt'];
    id = json['id'];
    imgUrl = json['pics'] != null ? json['pics'].cast<String>() : [];
    dynamic userInfo = userJson['user'];
    dynamic toUserInfo = userJson['toUser'];
    if (json['toUid'] == userInfo['uid']) {
      userInfo = userJson['toUser'];
      toUserInfo = userJson['user'];
    } else {
      userInfo = userJson['user'];
      toUserInfo = userJson['toUser'];
    }
    sendAvatar = userInfo['portrait'];
    sendName = userInfo['name'];
    sendUid = userInfo['uid'];
    takeAvatar = toUserInfo['portrait'];
    takeName = toUserInfo['name'];
    takeUid = toUserInfo['uid'];
    debugLog("${sendAvatar}====${takeAvatar}");
  }

  String? content;
  num? contentType;
  String? createdAt;
  String? id;
  List<String>? imgUrl;
  bool? isRead;
  String? sendAvatar;
  String? sendName;
  num? sendUid;
  String? sessionId;
  String? takeAvatar;
  String? takeName;
  num? takeUid;

  String get messageType {
    if (contentType == 1) {
      return "推广";
    } else if (contentType == 2) {
      return "提现";
    } else if (contentType == 3) {
      return "审核";
    } else if (contentType == 4) {
      return "大V审核";
    } else if (contentType == 5) {
      return "账号封禁";
    } else if (contentType == 6) {
      return "禁止上传";
    } else {
      return "官方";
    }
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['content'] = content;
    map['contentType'] = contentType;
    map['createdAt'] = createdAt;
    map['id'] = id;
    map['imgUrl'] = imgUrl;
    map['isRead'] = isRead;
    map['sendAvatar'] = sendAvatar;
    map['sendName'] = sendName;
    map['sendUid'] = sendUid;
    map['sessionId'] = sessionId;
    map['takeAvatar'] = takeAvatar;
    map['takeName'] = takeName;
    map['takeUid'] = takeUid;
    return map;
  }

  String? get headerImg => '${type == ChatMessageType.received ? takeAvatar : sendAvatar}';
  String? get name => type == ChatMessageType.received ? takeAvatar : sendName;
}
